package AES

import (
	"encoding/base64"
)

type b64 struct {
}

func (e *b64) EncryptECB(plaintext, key string) (string, error) {
	bytes, err := ECB.Encrypt([]byte(plaintext), []byte(key))
	if err != nil {
		return "", err
	}

	// 转换为BASE64
	return base64.StdEncoding.EncodeToString(bytes), nil
}

func (e *b64) DecryptECB(base64Str string, key string) (string, error) {
	// 将BASE64转换为数组
	encrypted, err := base64.StdEncoding.DecodeString(base64Str)
	if err != nil {
		return "", err
	}

	bytes, err := ECB.Decrypt(encrypted, []byte(key))
	if err != nil {
		return "", err
	}

	return string(bytes), nil
}
